package create_thread;

import java.util.concurrent.Callable;

/*
让这个类实现Callable接口
 */
public class MyCallable implements Callable<String> {
    // 重写call方法
    private int n;

    public MyCallable(int n) {
        this.n = n;
    }

    public MyCallable() {
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    @Override
    public String call() throws Exception {
        //描述线程的任务，返回线程执行返回的结果
        //需求：求1-n的和
        int sum = 0;
        for (int i = 1; i < n+1; i++) {
            sum += i;
        }
        return "1-n的和" +sum ;
    }
}
